home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc1 / maprz2_e.lha / MapRZ2_EVD1_1 / Source / MapRZ2.asm < prev    next >
Assembly Source File  |  1996-03-27  |  16KB  |  671 lines

  1. *
  2. * MapRZ2.asm CN20.12.95-02.01.95
  3. *
  4.  
  5.         MACHINE    68030
  6.  
  7.  
  8. ;*** Exec function offsets ***
  9.  
  10. Supervisor    equ    -$001E
  11. Disable        equ    -$0078
  12. Enable        equ    -$007E
  13. AllocMem    equ    -$00c6
  14. FreeMem        equ    -$00d2
  15. CloseLibrary    equ    -$019e
  16. OpenLibrary    equ    -$0228
  17.  
  18.  
  19. ;*** other constants ***
  20.  
  21. RB_BOARDADDRESS    equ    $2E                ;offset in RetinaBase
  22. RB_SEG_ADDRESS    equ    $32                ;offset in RetinaBase
  23.  
  24. MEMF_PUBLIC     equ    (1<<0)
  25.  
  26. SIZE_32K    equ    $00008000
  27. SIZE_4M        equ    $00400000
  28.  
  29. MASK_32K    equ    $00007fff
  30. MASK_128K    equ    $0001ffff
  31. MASK_4M        equ    $003fffff
  32.  
  33. RETINAMEMSIZE    equ    SIZE_4M                ;maximum amount of memory is 4 Mb
  34.  
  35. RETINA_REGNUM    equ    $43C4                ;choose a Retina hardware register at BoardAddress + this offset
  36. RETINA_REGVAL    equ    $03C4                ;access the chosen Retina hardware register
  37.  
  38. SEG_PTR_0H    equ    $18                ;Retina register numbers for RETINA_REGNUM
  39. SEG_PTR_0L    equ    $19                ;(used to control the 64k memory window)
  40. SEG_PTR_1H    equ    $1c
  41. SEG_PTR_1L    equ    $1d
  42. SEG_MODE    equ    $1e
  43. SEG_CTRL1    equ    $2
  44. SEG_CTRL2    equ    $20
  45. SEG_CTRL3    equ    $26
  46.  
  47. MASK_SEG_MODE    equ    %00001100            ;bits not used for segment mode
  48. MODE_TWO_SEG    equ    %11010011            ;sets two 32k segments mode
  49.  
  50. SEG_0_OFFSET    equ    $00010000            ;offsets of 32K segments
  51. SEG_1_OFFSET    equ    $00018000            ;relative to Retina board address
  52.  
  53.  
  54. ;*** constants for MMU usage ***
  55.  
  56. TIA        equ    8                ;  4Gb / 256 =  16Mb
  57. TIB        equ    6                ; 16Mb /  64 = 256Kb
  58. TIC        equ    3                ;256Kb /   8 =  32Kb
  59. TID        equ    0                ;(no D-Level used)
  60.  
  61. PAGE_SHIFT    equ    15                ;2^15 = 32K
  62. PAGE_SIZE    equ    1<<PAGE_SHIFT            ;one page is 32k big
  63.  
  64. A_ENTRIES    equ    (1<<TIA)            ;number of table entries at each level
  65. B_ENTRIES    equ    (1<<TIB)
  66. C_ENTRIES    equ    (1<<TIC)
  67.  
  68. A_TSIZE        equ    A_ENTRIES*4            ;size of one table at each level
  69. B_TSIZE        equ    B_ENTRIES*4            ;(using short descriptors)
  70. C_TSIZE        equ    C_ENTRIES*4
  71.  
  72. C_PSIZE        equ    PAGE_SIZE            ;size of pages at each level
  73. B_PSIZE        equ    C_PSIZE<<TIC
  74. A_PSIZE        equ    B_PSIZE<<TIB
  75.  
  76. A_OFFSET    equ    0                ;offsets in table mem block
  77.                             ;
  78. B_16M1_OFFSET    equ    A_OFFSET + A_TSIZE        ;first 16 Mb (standard Amiga mem)
  79. B_16M2_OFFSET    equ    B_16M1_OFFSET + B_TSIZE        :second 16 Mb (used for Retina)
  80.                             ;
  81. C_AC1_OFFSET    equ    B_16M2_OFFSET + B_TSIZE        ;AutoConfig 00e80000-00ebffff
  82. C_AC2_OFFSET    equ    C_AC1_OFFSET + C_TSIZE        ;AutoConfig 00ec0000-00efffff
  83. C_RB_OFFSET     equ    C_AC2_OFFSET + C_TSIZE        ;mirrored Retina board
  84. C_RL_OFFSET    equ    C_RB_OFFSET + C_TSIZE        ;4Mb linear Retina RAM
  85.                             ;
  86. TABLE_SIZE    equ    C_RL_OFFSET + 16*C_TSIZE    ;end and size of table
  87.  
  88. A_START        equ    $00000000            ;table entries point to these
  89.                             ;addresses in the logical mem space
  90. B_16M1_START    equ    $00000000            ;
  91. B_16M2_START    equ    $01000000            ;
  92.                             ;
  93. C_AC1_START    equ    $00e80000            ;
  94. C_AC2_START    equ    $00ec0000            ;
  95. C_RB_START    equ    $01000000            ;
  96. C_RL_START    equ    $01c00000            ;
  97.  
  98. PAGE_PTR_MASK    equ    $FFFFFF00            ;low descriptor byte is not part of ptr
  99. TABLE_PTR_MASK    equ    $FFFFFFF0            ;low 4 bits are not part of ptr
  100. TABLE_ALIGN    equ    $10                ;tables have to be aligned at 16 bytes boundary
  101.  
  102. PG_CI        equ    1<<6                ;page attributes: cache inhibit
  103. PG_M        equ    1<<4                ;modified
  104. PG_U        equ    1<<3                ;used
  105. PG_WP        equ    1<<2                ;write protect
  106.  
  107. SHORT_INVALID    equ    $BAD00000            ;DT bits = 00 = INVALID
  108.  
  109. DT_INVALID    equ    $0                ;descriptor types: invalid descriptor
  110. DT_PAGE        equ    $1                ;page descriptor
  111. DT_VALID_4BYTE    equ    $2                ;table pointer to short table
  112. DT_VALID_8BYTE    equ    $3                ;table pointer to long table
  113.  
  114. TC_ENABLE    equ    1<<31                ;codes for TC register
  115. TC_PSIZE    equ    (%1111)<<20            ;select 32K pages
  116. TC_TIA        equ    TIA<<12
  117. TC_TIB        equ    TIB<<8
  118. TC_TIC        equ    TIC<<4
  119. TC_TID        equ    TID
  120.  
  121.  
  122.  
  123.  
  124.         SECTION segment0,CODE
  125.  
  126. ;************
  127. ;main program
  128. ;************
  129.  
  130. main        movem.l D2-D7/A2-A6,-(SP)        ;save regs
  131.  
  132.         bsr    retina_addr            ;read Retina board address
  133.         tst.l    d0
  134.         bne    1$
  135.  
  136.         bsr    alloc_mem            ;allocate memory
  137.         tst.l    d0
  138.         bne    1$
  139.  
  140.         bsr    gen_MMU_tree            ;generate MMU tree
  141.  
  142.         bsr    turn_it_on            ;turn mapping on
  143.  
  144.         movem.l (SP)+,D2-D7/A2-A6        ;restore regs
  145.         moveq    #0,d0                ;returncode = 0,
  146.         rts
  147.  
  148. 1$        movem.l (SP)+,D2-D7/A2-A6        ;restore regs
  149.         moveq    #-1,d0                ;returncode = -1,
  150.         rts
  151.  
  152.  
  153.  
  154.  
  155. ;************************
  156. ;get Retina board address
  157. ;************************
  158.  
  159. retina_addr    ;open RetinaBase
  160.         lea    RetinaName,a1
  161.         moveq    #3,d0
  162.         move.l    (4).w,a6
  163.         jsr    OpenLibrary(a6)
  164.         move.l    d0,RetinaBase
  165.         beq    1$
  166.  
  167.         ;get address
  168.         move.l    d0,a0
  169.         move.l    RB_BOARDADDRESS(a0),BoardAddress
  170.  
  171.         ;close RetinaBase
  172.         move.l    RetinaBase,a1            
  173.         move.l    (4).w,a6
  174.         jsr    CloseLibrary(a6)
  175.  
  176.         moveq    #0,d0
  177.         rts
  178.  
  179. 1$        moveq    #-1,d0
  180.         rts
  181.  
  182.  
  183.  
  184.  
  185. ;***************
  186. ;allocate memory
  187. ;***************
  188.  
  189. alloc_mem    ;allocate memory
  190.         move.l    (4).w,a6
  191.         move.l    #end_bus_err_handler,d0
  192.         sub.l    #bus_err_handler,d0
  193.         add.l    #TABLE_ALIGN+TABLE_SIZE,d0
  194.         move.l    d0,BlockSize
  195.         move.l    #MEMF_PUBLIC,d1
  196.         jsr    AllocMem(a6)
  197.         move.l    d0,MemBlock
  198.                 beq     1$
  199.  
  200.         ;align table at 16 bytes boundary
  201.         and.l    #TABLE_PTR_MASK,d0
  202.         add.l    #TABLE_ALIGN,d0
  203.         move.l    d0,TableStart
  204.  
  205.         ;remember end of table / begin of own Bus Error handler
  206.         add.l    #TABLE_SIZE,d0
  207.         move.l    d0,HandlerStart
  208.  
  209.         moveq    #0,d0
  210.         rts
  211.  
  212. 1$        moveq    #-1,d0
  213.         rts
  214.  
  215.  
  216.  
  217.  
  218. ;*****************
  219. ;generate MMU tree
  220. ;*****************
  221.  
  222. gen_MMU_tree    move.l    TableStart,a3            ;start of whole tree (stays in a3 until end of subroutine)
  223.  
  224.         ;A table
  225.         move.l    a3,a0
  226.         move.w    #A_ENTRIES,d0
  227.         move.l    #DT_PAGE+A_START,d1
  228. 1$        move.l    d1,(a0)+
  229.         add.l    #A_PSIZE,d1
  230.         subq.w    #1,d0
  231.         bne    1$
  232.  
  233.         ;A exceptions
  234.         move.l  a3,d0
  235.         add.l    #DT_VALID_4BYTE+B_16M1_OFFSET,d0
  236.         move.l    d0,(a3)                ;pointer to B_16M1
  237.         add.l    #B_TSIZE,d0
  238.         move.l    d0,4(a3)            ;pointer to B_16M2
  239.  
  240.  
  241.         ;B_16M1 table
  242.         move.l  a3,a2
  243.         add.l    #B_16M1_OFFSET,a2        ;start of B_16M1 table
  244.  
  245.         move.l  a2,a0
  246.         move.w    #B_ENTRIES,d0
  247.         move.l    #DT_PAGE+B_16M1_START,d1
  248. 2$        move.l    d1,(a0)+
  249.         add.l    #B_PSIZE,d1
  250.         subq.w  #1,d0
  251.         bne    2$
  252.  
  253.         ;B_16M1 exceptions
  254.         move.l    a2,a0                ;don't cache chip RAM
  255.         move.w    #$200000/B_PSIZE,d0        ;number of chip RAM pages
  256. 3$        add.l    #PG_CI,(a0)+
  257.         subq.w    #1,d0
  258.         bne    3$
  259.  
  260.         add.l    #PG_CI,$00bc0000/B_PSIZE*4(a2)    ;don't cache CIAs
  261.         add.l    #PG_CI,$00dc0000/B_PSIZE*4(a2)    ;don't cache hardware clock and custom chips
  262.  
  263.         move.l  a3,d0
  264.         add.l    #DT_VALID_4BYTE+C_AC1_OFFSET,d0
  265.         move.l    d0,C_AC1_START/B_PSIZE*4(a2)    ;pointer to C_AC1
  266.         add.l    #C_TSIZE,d0
  267.         move.l    d0,C_AC2_START/B_PSIZE*4(a2)    ;pointer to C_AC2
  268.  
  269.         add.l   #PG_WP,$00f80000/B_PSIZE*4(a2)    ;write protect ROM
  270.         add.l   #PG_WP,$00fc0000/B_PSIZE*4(a2)    ;(FastROM option would be useful!)
  271.  
  272.  
  273.         ;B_16M2 table
  274.         move.l  a3,a2
  275.         add.l    #B_16M2_OFFSET,a2        ;start of B_16M2 table
  276.  
  277.         move.l  a2,a0
  278.         move.w    #B_ENTRIES,d0
  279. 4$        move.l    #SHORT_INVALID,(a0)+
  280.         subq.w  #1,d0
  281.         bne    4$
  282.  
  283.         ;B_16M2 exceptions
  284.         move.l  a3,d0
  285.         add.l    #DT_VALID_4BYTE+C_RB_OFFSET,d0
  286.         move.l    d0,(a2)                ;pointer to C_RB
  287.  
  288.         move.l  a2,a0
  289.         add.l    #(C_RL_START-B_16M2_START)/B_PSIZE*4,a0
  290.         move.l    a3,d1
  291.         add.l    #DT_VALID_4BYTE+C_RL_OFFSET,d1
  292.         move.w    #RETINAMEMSIZE/B_PSIZE,d0
  293.  
  294. 5$        move.l    d1,(a0)+            ;16 pointers to C_RL
  295.         add.l    #C_TSIZE,d1
  296.         subq.w    #1,d0
  297.         bne    5$
  298.  
  299.  
  300.         ;C_AC tables
  301.         move.l  a3,a2
  302.         add.l    #C_AC1_OFFSET,a2        ;start of C_AC table
  303.  
  304.         move.l    a2,a0
  305.         move.w    #C_ENTRIES*2,d0
  306.         move.l    #DT_PAGE+PG_CI+C_AC1_START,d1
  307. 6$        move.l    d1,(a0)+
  308.         add.l    #C_PSIZE,d1
  309.         subq.w    #1,d0
  310.         bne    6$
  311.  
  312.         ;C_AC things to remember
  313.         move.l    BoardAddress,d0
  314.         sub.l    #C_AC1_START,d0
  315.         moveq    #PAGE_SHIFT-2,d1
  316.         lsr.l    d1,d0                ;divide by page size and multiply by 4 to get long word offset
  317.         add.l    a2,d0
  318.         move.l    d0,MMU_RB
  319.  
  320.         move.l    d0,a0                ;remember valid MMU_RB table entries
  321.         lea    ValidMMU_RB,a1
  322.         move.l    (a0)+,(a1)+
  323.         move.l    (a0)+,(a1)+
  324.         move.l    (a0)+,(a1)+
  325.         move.l    (a0),(a1)
  326.  
  327.  
  328.         ;C_RB table
  329.         move.l  a3,a2
  330.         add.l    #C_RB_OFFSET,a2            ;start of C_RB table
  331.  
  332.         move.l    a2,a0
  333.         move.w    #C_ENTRIES,d0
  334. 7$        move.l    #SHORT_INVALID,(a0)+
  335.         subq.w    #1,d0
  336.         bne    7$
  337.  
  338.         ;C_RB exceptions
  339.         move.l    a2,a1
  340.         move.l    #DT_PAGE+PG_CI,d0
  341.         add.l    BoardAddress,d0
  342.         move.l    d0,(a1)+
  343.         add.l    #PAGE_SIZE,d0
  344.         move.l    d0,(a1)+
  345.         add.l    #PAGE_SIZE,d0
  346.         move.l    d0,(a1)+
  347.         add.l    #PAGE_SIZE,d0
  348.         move.l    d0,(a1)
  349.  
  350.  
  351.         ;C_RL tables
  352.         move.l  a3,a2
  353.         add.l    #C_RL_OFFSET,a2            ;start of C_RL table
  354.  
  355.         move.l    a2,a0
  356.         move.w    #C_ENTRIES*16,d0
  357. 8$        move.l    #SHORT_INVALID,(a0)+
  358.         subq.w    #1,d0
  359.         bne    8$
  360.  
  361.         ;C_AC things to remember
  362.         move.l    a2,MMU_RL
  363.  
  364.         rts
  365.  
  366.  
  367.  
  368.  
  369. ;***************
  370. ;turn mapping on
  371. ;***************
  372.  
  373. turn_it_on    move.l    (4).w,a6
  374.         jsr    Disable(a6)            ;disable interrupts and task scheduling
  375.  
  376.         lea    use_MMU_tree,a5
  377.         jsr    Supervisor(a6)
  378.  
  379.         move.l    CurrentVBR,a3
  380.         move.l    $8(a3),OldHandler        ;is called from new handler
  381.  
  382.         lea    bus_err_handler,a0
  383.         lea    end_bus_err_handler,a1
  384.         move.l    HandlerStart,a2
  385.  
  386. 1$        move.w    (a0)+,(a2)+            ;copy handler
  387.         cmp.l    a0,a1
  388.         bne    1$
  389.  
  390.         move.l    HandlerStart,$8(a3)        ;activate own handler
  391.  
  392.         jsr    Enable(a6)            ;enable interrupts and task scheduling again
  393.         rts
  394.  
  395.  
  396.  
  397.  
  398. ;turn MMU tree on (Supervisor mode)
  399.  
  400. use_MMU_tree    lea    OffTC,a0
  401.         pmove.l    (a0),TC                ;disable MMU translation
  402.  
  403.         lea    NewCRP,a0
  404.         pmove.d    (a0),CRP            ;point MMU to our new tree
  405.  
  406.         lea    NewTC,a0
  407.         pmove.l    (a0),TC                ;re-enable MMU with new tree
  408.  
  409.         movec.l    VBR,d0                ;get VBR pointer
  410.         move.l    d0,CurrentVBR
  411.         rte
  412.  
  413.  
  414.  
  415.  
  416. ;*****************
  417. ;Bus Error handler
  418. ;*****************
  419.  
  420. bus_err_handler    movem.l    d0-d1/d6-d7/a0-a5,-(sp)        ;save regs
  421.         move.l    (4+6)*4+$10(sp),d7        ;get faulty address that caused exception
  422.  
  423.         move.l    d7,d0                ;faulty address
  424.         and.l    #~MASK_128K,d0            ;mask out lower bits; doesn't work, if Retina hardware starts at an odd 64k page!
  425.         cmp.l    BoardAddress(pc),d0        ;Retina board hardware accessed?
  426.         beq    board_acc            ;yes
  427.  
  428.         move.l    d7,d0                ;faulty address
  429.         and.l    #~MASK_4M,d0            ;mask out lower bits
  430.         cmpi.l    #C_RL_START,d0            ;linear Retina RAM accessed?
  431.         beq    linear_RAM_acc            ;yes
  432.  
  433.         movem.l    (sp)+,d0-d1/d6-d7/a0-a5        ;restore regs
  434.         move.l    OldHandler(pc),-(sp)        ;jump to normal Bus Error handler
  435.         rts
  436.  
  437.  
  438.  
  439.  
  440. ;Retina board hardware accessed -> change to segmented mode
  441.  
  442. board_acc    ori.w   #$0700,SR            ;turn interrupts off (are turned on again by rte)
  443.         move.l    #C_RB_START+RETINA_REGVAL,a4    ;access the chosen Retina hardware register
  444.         move.l    #C_RB_START+RETINA_REGNUM,a5    ;choose Retina hardware register
  445.  
  446.         lea    RetinaSegCtrl3(pc),a0
  447.         move.b    #SEG_CTRL3,(a5)            ;restore Retina registers
  448.         move.b    (a0),(a4)
  449.         move.b    #SEG_CTRL2,(a5)
  450.         move.b    -(a0),(a4)
  451.         move.b    #SEG_CTRL1,(a5)
  452.         move.b    -(a0),(a4)
  453.         move.b    #SEG_MODE,(a5)
  454.         move.b    -(a0),(a4)
  455.         move.b    #SEG_PTR_1L,(a5)
  456.         move.b    -(a0),(a4)
  457.         move.b    #SEG_PTR_1H,(a5)
  458.         move.b    -(a0),(a4)
  459.         move.b    #SEG_PTR_0L,(a5)
  460.         move.b    -(a0),(a4)
  461.         move.b    #SEG_PTR_0H,(a5)
  462.         move.b    -(a0),(a4)
  463.         move.b    -(a0),(a5)            ;register B after all A registers
  464.  
  465.         lea    MMU_S0(pc),a2            ;set MMU_RL table entry 0 invalid
  466.         move.l  (a2),a0                ;is entry already invalid?
  467.         cmpa.l    #0,a0                ;(movea doesn't set flags, tst.l ax doesn't exist)
  468.         beq    1$                ;yes
  469.         move.l    #SHORT_INVALID,(a0)        ;mark MMU table entry
  470.         move.l    #0,(a2)                ;clear pointer
  471. 1$
  472.         lea    MMU_S1(pc),a2            ;set MMU_RL table entry 1 invalid
  473.         move.l  (a2),a0                ;is entry already invalid?
  474.         cmpa.l    #0,a0                ;(movea doesn't set flags, tst.l ax doesn't exist)
  475.         beq    2$                ;yes
  476.         move.l    #SHORT_INVALID,(a0)        ;mark MMU table entry
  477.         move.l    #0,(a2)                ;clear pointer
  478. 2$
  479.         lea    ValidMMU_RB(pc),a0        ;set MMU_RB table entries valid
  480.         move.l    MMU_RB(pc),a1
  481.         move.l    (a0)+,(a1)+
  482.         move.l    (a0)+,(a1)+
  483.         move.l    (a0)+,(a1)+
  484.         move.l    (a0),(a1)
  485.  
  486.         pflusha                    ;flush MMU cache
  487.         movem.l    (sp)+,d0-d1/d6-d7/a0-a5        ;restore regs
  488.         rte                    ;restart instruction
  489.  
  490.  
  491.  
  492.  
  493. ;linear Retina RAM accessed
  494.  
  495. linear_RAM_acc    ori.w   #$0700,SR            ;turn interrupts off (are turned on again by rte)
  496.         move.l    #C_RB_START+RETINA_REGVAL,a4    ;access the chosen Retina hardware register
  497.         move.l    #C_RB_START+RETINA_REGNUM,a5    ;choose Retina hardware register
  498.  
  499.         move.l    MMU_S0(pc),d0            ;is linar mode already on? (tst.b d(pc) doesn't exist)
  500.         bne    linear_is_on            ;yes
  501.         move.l    MMU_S1(pc),d0            ;is linar mode already on? (tst.b d(pc) doesn't exist)
  502.         bne    linear_is_on            ;yes
  503.  
  504.  
  505.         ;change to linear mode
  506.  
  507.         lea    RetinaRegB(pc),a0        ;save Retina registers
  508.         move.b    (a5),(a0)+            ;register B before all A registers
  509.         move.b    #SEG_PTR_0H,(a5)
  510.         move.b    (a4),(a0)+
  511.         move.b    #SEG_PTR_0L,(a5)
  512.         move.b    (a4),(a0)+
  513.         move.b    #SEG_PTR_1H,(a5)
  514.         move.b    (a4),(a0)+
  515.         move.b    #SEG_PTR_1L,(a5)
  516.         move.b    (a4),(a0)+
  517.         move.b    #SEG_MODE,(a5)
  518.         move.b    (a4),(a0)+
  519.         move.b    (a4),d0                ;set two 32k segments mode
  520.         and.b    #MASK_SEG_MODE,d0
  521.         or.b    #MODE_TWO_SEG,d0
  522.         move.b    d0,(a4)
  523.         move.b    #SEG_CTRL1,(a5)
  524.         move.b    (a4),(a0)+
  525.         move.b    #$f,(a4)            ;set normal mode
  526.         move.b    #SEG_CTRL2,(a5)
  527.         move.b    (a4),(a0)+
  528.         bset.b    #1,(a4)                ;set normal mode
  529.         move.b    #SEG_CTRL3,(a5)
  530.         move.b    (a4),(a0)
  531.         andi.b    #$f5,(a4)            ;set normal mode
  532.  
  533.         move.l    #SHORT_INVALID,d0        ;set MMU_RB table entries invalid
  534.         move.l    MMU_RB(pc),a0
  535.         move.l    d0,(a0)+
  536.         move.l    d0,(a0)+
  537.         move.l    d0,(a0)+
  538.         move.l    d0,(a0)
  539.  
  540.  
  541. linear_is_on    move.l    d7,d0                ;faulty address
  542.         and.l    #MASK_4M&~MASK_32K,d0        ;mask out upper & lower bits
  543.         move.l    d0,d6
  544.         lsr.l    #6,d6                ;address for Retina segment pointer
  545.  
  546.         moveq    #PAGE_SHIFT-2,d1        ;replaces 'divu.l #C_PSIZE/4,d0'
  547.         lsr.l    d1,d0                ;divide by page size and multiply by 4 to get long word offset
  548.         add.l    MMU_RL(pc),d0            ;add MMU_RL base address
  549.         move.l    d0,a3                ;address in MMU table
  550.  
  551.         move.b    NextSegment(pc),d0        ;which segment is next? (tst.b d(pc) doesn't exist)
  552.         bne    segment_1
  553.  
  554.  
  555.         ;use segment 0
  556.  
  557.         lea    MMU_S0(pc),a2            ;set old MMU_RL table entry 0 invalid
  558.         move.l  (a2),a0                ;is entry already invalid?
  559.         cmpa.l    #0,a0                ;(movea doesn't set flags, tst.l ax doesn't exist)
  560.         beq    1$                ;yes
  561.         move.l    #SHORT_INVALID,(a0)        ;mark MMU table entry
  562. 1$
  563.         move.l    ValidMMU_Seg0(pc),(a3)        ;set new MMU_RL table entry 0 valid
  564.         move.l    a3,(a2)                ;store its address in MMU_S0
  565.  
  566.         move.b    #SEG_PTR_0L,(a5)        ;write address into Retina segment pointer
  567.         move.b    d6,(a4)
  568.         lsr.w    #8,d6
  569.         move.b    #SEG_PTR_0H,(a5)
  570.         move.b    d6,(a4)
  571.  
  572.         lea    NextSegment(pc),a0        ;set next segment to 1
  573.         move.b    #1,(a0)
  574.  
  575.         pflusha                    ;flush MMU cache
  576.         movem.l    (sp)+,d0-d1/d6-d7/a0-a5        ;restore regs
  577.         rte                    ;restart instruction
  578.  
  579.  
  580.         ;use segment 1
  581.  
  582. segment_1    lea    MMU_S1(pc),a2            ;set old MMU_RL table entry 1 invalid
  583.         move.l  (a2),a0                ;is entry already invalid?
  584.         cmpa.l    #0,a0                ;(movea doesn't set flags, tst.l ax doesn't exist)
  585.         beq    1$                ;yes
  586.         move.l    #SHORT_INVALID,(a0)        ;mark MMU table entry
  587. 1$
  588.         move.l    ValidMMU_Seg1(pc),(a3)        ;set new MMU_RL table entry 1 valid
  589.         move.l    a3,(a2)                ;store its address in MMU_S1
  590.  
  591.         sub.w    #SIZE_32K>>6,d6            ;subtract 32K>>6 due to second segment
  592.         move.b    #SEG_PTR_1L,(a5)        ;write address into Retina segment pointer
  593.         move.b    d6,(a4)
  594.         lsr.w    #8,d6
  595.         move.b    #SEG_PTR_1H,(a5)
  596.         move.b    d6,(a4)
  597.  
  598.         lea    NextSegment(pc),a0        ;set next segment to 0
  599.         move.b    #0,(a0)
  600.  
  601.         pflusha                    ;flush MMU cache
  602.         movem.l    (sp)+,d0-d1/d6-d7/a0-a5        ;restore regs
  603.         rte                    ;restart instruction
  604.  
  605.  
  606.  
  607.  
  608. ;values provided by the main program
  609.  
  610. OldHandler    ds.l    1                ;pointer to old handler
  611.  
  612. BoardAddress    ds.l    1                ;Retina board address
  613.  
  614. MMU_RB        ds.l    1                ;MMU tables to Retina board
  615. MMU_RL        ds.l    1                ;MMU tables to linear Retina RAM
  616.  
  617. ValidMMU_RB    ds.l    1                ;valid MMU_RB entries to Retina board
  618.         ds.l    1                ;
  619. ValidMMU_Seg0    ds.l    1                ;valid MMU entry to 32K segment No. 0
  620. ValidMMU_Seg1    ds.l    1                ;valid MMU entry to 32K segment No. 1
  621.  
  622.  
  623. ;values filled in by exception handler
  624.  
  625. MMU_S0        dc.l    0                ;MMU table to segment No. 0 in the linear Retina RAM
  626. MMU_S1        dc.l    0                ;MMU table to segment No. 1 in the linear Retina RAM
  627.  
  628. NextSegment    dc.b    0                ;next segment to choose
  629.  
  630. RetinaRegB    ds.b    1                ;copies of important Retina registers
  631. RetinaPtr0h    ds.b    1
  632. RetinaPtr0l    ds.b    1
  633. RetinaPtr1h    ds.b    1
  634. RetinaPtr1l    ds.b    1
  635. RetinaSegMode    ds.b    1
  636. RetinaSegCtrl1    ds.b    1
  637. RetinaSegCtrl2    ds.b    1
  638. RetinaSegCtrl3    ds.b    1
  639.  
  640.  
  641.         even
  642. end_bus_err_handler                    ;copy handler up to here
  643.  
  644.  
  645.  
  646.  
  647. ;library names
  648.  
  649. RetinaName    dc.b    "retina.library",0
  650.  
  651.  
  652. ;library base pointers
  653.  
  654. RetinaBase    ds.l    1
  655.  
  656.  
  657. ;other data
  658.  
  659. MemBlock    ds.l    1                ;reserved mem block
  660. BlockSize    ds.l    1                ;size of mem block
  661. HandlerStart    ds.l    1                ;start of own Bus Error handler
  662. OffTC        dc.l    $0                ;TC register value to turn MMU off
  663. NewTC        dc.l    TC_ENABLE+TC_PSIZE+TC_TIA+TC_TIB+TC_TIC+TC_TID    ;new TC-Register value
  664. NewCRP        dc.l    $7FFF<<16+DT_VALID_4BYTE    ;\ new CRP-Register value with
  665. TableStart    ds.l    1                ;/ begin of MMU tree
  666. CurrentVBR    ds.l    1
  667.  
  668. VersionString    dc.b    "$VER: MapRZ2 1.0 (02.01.95) Christoph Niedeggen",$00
  669.  
  670.         END
  671.